package com.jams.goodox.activity.home;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.utils.StyleUtil;
import com.jams.library.commonAdapter.ListCommonAdapter;
import com.jams.library.commonAdapter.ListCommonViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Created by Administrator on 2017/11/11.
 */

public class ChooseAddressSecondActivity extends BaseActivity {
    @Bind(R.id.list_address)
    ListView listAddress;

    private List<CityResp.ResultBean> resultBeanList;
    private ListCommonAdapter listCommonAdapter;
    private String city;
    private String cityId;

    @Override
    protected int getLayoutId() {
        return R.layout.choose_address_activity;
    }

    @Override
    protected void init() {
        setAdapter();
        getData();
    }

    private void setAdapter(){
        StyleUtil.init(this, "选择区域");
        resultBeanList=new ArrayList<>();
        listCommonAdapter=new ListCommonAdapter<CityResp.ResultBean>(this,resultBeanList,R.layout.only_textview) {
            @Override
            public void convert(ListCommonViewHolder helper, CityResp.ResultBean item, int position) {
                helper.setText(R.id.tv_item,item.getName());
            }
        };
        listAddress.setAdapter(listCommonAdapter);
        listAddress.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent(ChooseAddressSecondActivity.this,ChooseAddressLastActivity.class);
                intent.putExtra("id",resultBeanList.get(position).getId());
                intent.putExtra("name",city+resultBeanList.get(position).getName());
                startActivity(intent);
            }
        });
    }

    private void getData(){
        cityId=getIntent().getStringExtra("id");
        city=getIntent().getStringExtra("name");
    }

}
